<template>
	<view class="fi">
		<view class="fi-wrapper" v-for="(item,index) in detail.orderlog" :key="index">
			<view class="sub-item">
				<view class="sub-child">
					<image :src="item.icon || '/static/img/feizhi.png'" class="sub-img"></image>
					<view class="sub-con">
						<view style="color: rgba(36, 36, 36, 1);font-size: 15px;font-weight: bold;">{{item.name}}</view>
						<view style="color: rgba(36, 36, 36, 1);padding-top: 12px;">单价：¥{{item.money}}/公斤</view>
						<view style="color: rgba(36, 36, 36, 1);">重量：{{item.ordertype}}</view>
					</view>
				</view>
			</view>
			<view class="fi-input">
				<view class="par-iphone">
					<view class="iphone-text">实际单价</view>
					<input type="digit" v-model="item.relprice" @input="changePrice(item.id)" placeholder="请输入实际单价"/>
				</view>
				<view class="par-iphone">
					<view class="iphone-text">实际重量</view>
					<input type="digit" v-model="item.relweight" @input="changePrice(item.id)" placeholder="请输入实际重量"/>
				</view>
				<view class="par-iphone">
					<view class="iphone-text">实际总金额</view>
					<input type="digit" v-model="item.total" disabled/>
				</view>
			</view>
		</view>
		
		<view class="par-but" @click="confirmOrder()">确认</view>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				detail:'',
				itemTotal:{}
			}
		},
		onLoad(options){
			if(options.detail){
				this.detail = JSON.parse(options.detail)
				// let list = [{
				// 	id: 6,
				// 	money: "3.00",
				// 	name: "纯黄纸（如空调箱，快递箱等）",
				// 	ordertype: "25-50公斤",
				// 	type: 2,
				// }]
				// this.detail.orderlog = this.detail.orderlog.concat(list)
			}
		},
		computed:{
			total(){
				return function(value){
					let totalNum = 0
					console.log(this.detail.orderlog)
					this.detail.orderlog.forEach((val) => {
						if(value == val.id){
							if(val.relprice && val.relweight){
								totalNum = (val.relprice * val.relweight)
							}
						}
					})
					return totalNum.toFixed(2)
				}
			}
		},
		methods: {
			changePrice(id){
				console.log(id)
				this.detail.orderlog.forEach((val) => {
					if(id == val.id){
						if(val.relprice && val.relweight){
							let total = (val.relprice * val.relweight).toFixed(2)
							this.$set(val,'total',total)
						}
					}
				})
			},	
			confirmOrder(){
				let data = []
				this.detail.orderlog.forEach((val) => {
					if(val.relprice){
						data.push({id:val.id,price:val.relprice,weight:val.relweight})
					}
				})
				if(data.length == 0){
					uni.showToast({
						title:'请先填写实际单价，重量',
						icon:'none'
					})
					return
				}
				let formData = {
					orderid:this.detail.id,
					data:JSON.stringify(data)
				}
				uni.showLoading({})
				this.$http.confirmorder(formData).then(res => {
					uni.hideLoading()
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
					if(res.code == 0){
						setTimeout(() => {
							uni.navigateBack({})
						},1000)
					}
				})
			}
		}
	}
</script>

<style scoped>
.fi{
	width: 100%;
	padding-bottom: 80px;
	overflow-y: scroll;
}
.sub-item{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		background-color: #FFFFFF;
		padding: 20px;
		margin-bottom: 10px;
	}
	
	.sub-img{
		width: 50px;
		height: 50px;
		border-radius: 50%;
	}
	
		
	.sub-child{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		width: 100%;
	}
	.sub-con{
		    flex: 1;
			padding-left: 16px;
	}
	.fi-input{
		padding: 15px;
		background-color: rgba(250, 250, 250, 1);
	}
	.par-iphone:nth-of-type(1){
		 margin: 0;
	 }
	 
	  .par-iphone:last-child{ 
		   margin: 0;
	  }
	.par-iphone{
		display: flex;
		flex-direction: row;
		background-color: rgba(187, 187, 187, 0.1);
		height: 43px;
		border-radius: 5px;
		align-items: center;
		margin: 15px 0;
		    position: relative;
	}
	
	.iphone-text{
	color: #242424;
	font-size: 14px;
	padding: 0 12px;
	min-width: 158upx;
	}
	.uni-input-placeholder{
		font-size: 12px;
		    color: #898989;
	}
	.par-but{
		height:96upx;
	
	background: linear-gradient(124deg, #6AA7E8 0%, #3D9AFD 100%);
	
box-shadow: 0px 2px 4px 0px #1E75FF;
		border-radius:48upx;
		line-height: 96upx;
		text-align: center;
		font-size: 16px;
		color: #FFFFFF;
		margin: 50px auto 0 auto;
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 9;
	}
</style>
